<template>
  <div class="home-singer">
    <h3>热门歌手</h3>
    <div class="wrapper" ref="wrapper">
      <ul class="content" ref="content">
        <li
          v-for="(item, index) in listData"
          :key="index"
          @click="selectItem(item)"
        >
          <div class="cover">
            <van-image :src="item.singer_pic" radius="1rem" />
          </div>
          <span>{{ item.singer_name }}</span>
        </li>
      </ul>
    </div>
  </div>
</template>
<script>
import { betterScrollHorizontal } from "../../common/betterScroll";

export default {
  data() {
    return {
      listData: [],
    };
  },
  created() {
    this.getListData();
  },
  methods: {
    //获取到推荐歌单的数据
    getListData() {
      this.$request("get", "/singer/list").then((res) => {
        console.log(res);
        if (res.result == 100) {
          this.listData = res.data.list;
        }
        // console.log(this.listData);
        betterScrollHorizontal(
          this,
          this.$refs.wrapper,
          this.$refs.content,
          this.listData.length,
          10
        ); //调用横向滚动的方法
      });
    },
    selectItem(item) {
      const singerId = item.singer_mid;
      this.$router.push(`/singerhome/${singerId}`);
      this.$store.commit('saveSinger',item)
    },
    // betterScrollHorizontal(num,itemWidth){
    //     this.$refs.content.style.width = num * itemWidth + "rem";
    //     this.$nextTick(() => {
    //         this.scroll = new BScroll(this.$refs.wrapper, {
    //             startX:0,//横向滚动的开始位置
    //             scrollX:true,//横向滚动
    //             scrollY:false//关闭纵向滚动
    //             });
    //         });
    // },
  },
};
</script>
<style scoped>
.cover > span {
  position: absolute;
  right: 0.2rem;
  bottom: 0.4rem;
  background-color: rgb(212, 230, 136);
  color: white;
  font-size: 14px;
  border-radius: 1rem;
  width: 5rem;
  display: inline-block;
}
.cover {
  position: relative;
}
.wrapper {
  width: 100%;
  overflow: hidden;
}
/* .content{
     width: calc(12 * 10rem);
 } */
ul.content li {
  display: inline-block;
  width: 10rem;
  vertical-align: top;
}
ul.content li * {
  margin: 0.1rem;
}
ul.content li > span {
  font-size: 0.8rem;
  color: #54493b;
}
</style>





